import java.util.Scanner;

/**
 * 【程序43】   
 * 题目：计算字符串中子串出现的次数  
 * 例如：字符串abcewegwgegwefwre中we出现了2次；
 * 字符串aaawersfoitngjaa中aa出现了2次
 */
public class test43 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.print("请输入一个字符串：");
        String str1 = sc.next();
        char[] chars1 = str1.toCharArray();
        System.out.print("请输入子串：");
        String str2 = sc.next();
        char[] chars2 = str2.toCharArray();
        int count = 0;
        loop:
        for (int i = 0; i < chars1.length; i++) {
            int right = 0;
            for (int j = 0; j < chars2.length; j++) {
                if ((i + j) > chars1.length - 1)
                    break loop;
                if (chars2[j] == chars1[i + j]) {
                    right++;
                    if (right == chars2.length) {
                        count++;
                        i = i + str2.length() - 1;
                        break;
                    }
                }
            }
        }
        System.out.println(str2 + "出现了" + count + "次");
    }
}
